package com.ruoyi.toolbox.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.toolbox.domain.database.Table;
import com.ruoyi.toolbox.service.IDatabaseService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 数据管理
 *
 * @author tqfeiyang
 * @since 2024/11/26 14:27
 */
@RestController
@RequestMapping("/toolbox/database")
@RequiredArgsConstructor
public class DatabaseController extends BaseController
{
    private final IDatabaseService databaseService;

    /**
     * 查询数据表
     *
     * @return 操作结果
     */
    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('toolbox:database:list')")
    public R<List<Table>> selectTableList()
    {
        return R.ok(databaseService.selectTableList());
    }

    /**
     * 数据表优化
     *
     * @param list 数据表
     * @return 操作结果
     */
    @PostMapping("/optimize")
    @PreAuthorize("@ss.hasPermi('toolbox:database:optimize')")
    public R optimizeTableList(@RequestBody List<String> list)
    {
        databaseService.optimizeTableList(list);
        return R.ok();
    }

    /**
     * 数据表修复
     *
     * @param list 数据表
     * @return 操作结果
     */
    @PostMapping("/repair")
    @PreAuthorize("@ss.hasPermi('toolbox:database:repair')")
    public R repairTableList(@RequestBody List<String> list)
    {
        databaseService.repairTableList(list);
        return R.ok();
    }

}
